﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace com.ReinforceLab.AudioModem.LinkLayer
{
    /// <summary>
    /// FSK 変調信号生成クラス
    ///     動作条件：オーバサンプル8でのみ
    ///     LSb-first, StartBit '0', Data bits 8-bit, StopBit '1'
    ///     位相： 1ならそのまま、0なら反転 （検波すれば＋振幅が1、ー振幅が0に対応する、正論理）
    /// </summary>
    /*class Modulator
    {
        #region Variables
        readonly short[] _one_waveform;
        readonly short[] _zero_waveform;
        #endregion
            
        #region Construcotr            
        public Modulator()
        {                
            short max = (short)(short.MaxValue - 10);
            short max_2pi = (short)((short.MaxValue - 10) / Math.Sqrt(2));

            _one_waveform  = new short [] { 0, max, 0, (short)(-1 * max) };
            _zero_waveform = new short[]  { 0, max_2pi, max, max_2pi, 0, (short)(-1 * max_2pi), (short)(-1 * max), (short)(-1 * max_2pi) };
        }            
        #endregion

        #region Private methods
        #endregion

        #region Public methods
        public short[] Modulate(byte [] data)
        {
            var buf = new List<short>();
            // beat
            for (int i = 0; i < 8; i++)
                buf.AddRange(_one_waveform);

            // start bit '0', data bits, stop bit '1'
            for (int index = 0; index < data.Length; index++)
            {
                int b = ((int)data[index] << 1) | 0x0200;
                for (int i = 0; i < (8 + 2); i++)
                {
                    if((0x01 & b) == 0)
                        buf.AddRange(_zero_waveform);
                    else
                        buf.AddRange(_one_waveform); 
                    b = (b >> 1);
                }
            }

            // beat
            for (int i = 0; i < 4; i++)
                buf.AddRange(_one_waveform); 
            
            buf.Add(0);

            return buf.ToArray();
        }
        #endregion
    }*/
}
